package agent.monitors;

import org.snmp4j.smi.Integer32;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.Variable;

public class TorrentFile {
	//TORRENT FILE BRANCH
	private String hash;
	private int status;
	private String name;
	private int size;
	private int percent;
	private int downloaded;
	private int uploaded;
	private int downloadSpeed;
	private int uploadSpeed;
	private int eta;
	private int peersConnected;
	private int seedsConnected;
	
	public TorrentFile(String[] filteredFileData) {
		this.hash			= filteredFileData[0];							//colHash
		this.status			= Integer.parseInt(filteredFileData[1]);		//colStatus
		this.name			= filteredFileData[2];							//colName
		this.size			= (int)Long.parseLong(filteredFileData[3])/1024;//colSize
		this.percent		= Integer.parseInt(filteredFileData[4]);		//colPercent
		this.downloaded		= (int)Long.parseLong(filteredFileData[5])/1024;//colDownloaded
		this.uploaded		= (int)Long.parseLong(filteredFileData[6])/1024;//colUploaded
		this.uploadSpeed	= Integer.parseInt(filteredFileData[7]);		//colUploadSpeed
		this.downloadSpeed	= Integer.parseInt(filteredFileData[8]);		//colDownloadSpeed
		this.eta			= Integer.parseInt(filteredFileData[9]); 		//colEta
		this.peersConnected	= Integer.parseInt(filteredFileData[10]);		//colPeersConnected
		this.seedsConnected	= Integer.parseInt(filteredFileData[11]);		//colSeedsConnected
	}
	
	public String getHash(){
		return this.hash;
	}
	
	public Variable[] getVariableArray(){
		return new Variable[] {
					new OctetString(hash) , 
					new Integer32(status) , 
					new OctetString(name) , 
					new Integer32(size) , 
					new Integer32(percent) , 
					new Integer32(downloaded) , 
					new Integer32(uploaded) , 
					new Integer32(downloadSpeed) , 
					new Integer32(uploadSpeed) , 
					new Integer32(eta) , 
					new Integer32(peersConnected) , 
					new Integer32(seedsConnected)
			};
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null || !(obj instanceof TorrentFile)){
			return false;
		}
		else{
			TorrentFile compareObj = (TorrentFile)obj;
			if(compareObj.downloaded != this.downloaded ||
					compareObj.downloadSpeed != this.downloadSpeed ||
					compareObj.eta != this.eta ||
					this.hash.equals(compareObj.hash) ||
					this.name.equals(compareObj.name) ||
					compareObj.peersConnected != this.peersConnected ||
					compareObj.percent != this.percent ||
					compareObj.seedsConnected != this.seedsConnected ||
					compareObj.size != this.size ||
					compareObj.status != this.status ||
					compareObj.uploaded != this.uploaded ||
					compareObj.uploadSpeed != this.uploadSpeed){
				return false;
			}
			else {
				return true;
			}
		}
	}
}
